<?php

namespace App\Console\Commands;

use App\Models\RegisterPhone;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;


class AddRegisterPhone extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cc:add-register-phone';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
          User::query()
            //->whereHas('goldCharges')
            ->chunks(50, function (Collection $users) {

                if ($users->isEmpty()) return true;

                /**
                 * @var User $user
                 */
                foreach ($users as $user) {
                    RegisterPhone::create(['phone'=>$user->phone]);
                }

                return true;

            });
    }
}
